import datarover from "./datarover.mjs";
import { datarows } from "./table_helper.mjs";
import thin_render from "./thin_render.mjs";
export default function foreach_template(container, template) {
  // console.log({ container, template });
  if (typeof template.foreach === "string") {
    let d = datarover(template.data || container, template.foreach);
    // console.log(d);
    if (Array.isArray(d)) {
      d.forEach((row, index) => {
        // console.log(row, index);
        if (Array.isArray(template.t)) {
          template.t.forEach((item, index) => {
            thin_render(container, { ...item, data: row });
          });
        } else {
          thin_render(container, { ...template.t, data: row });
        }
      });
    }
  }
}
